﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace produccion.clases
{
    public class CLSMAELIN
    {
        string codlin_lin, nomlin_lin;
        Boolean logSeleccionado;

        public string CODLIN_LIN
        {
            get { return codlin_lin; }
            set { codlin_lin = value; }
        }

        public string NOMLIN_LIN
        {
            get { return nomlin_lin; }
            set { nomlin_lin = value; }
        }

        public Boolean LOGSELECCIONADO
        {
            get { return logSeleccionado; }
            set { logSeleccionado = value; }
        }

        MDOgeneral mod = new MDOgeneral();

        public Boolean ExisteLinea()
        {
            try
            {
                string query = "select codlin_lin from USU_FBR.MAELIN where codlin_lin ='" + CODLIN_LIN + "' AND LINPPAL_LIN = 'S' ORDER BY NOMLIN_LIN";
                if (mod.consulta(query).Rows.Count > 0)
                {
                    return true;
                }
                return false;
            } catch (Exception e) { throw e; }
        }

        public DataTable Consultar()
        {
            try
            {
                string query = "select codlin_lin as Codigo, nomlin_lin as Nombre from USU_FBR.MAELIN where codlin_lin ='" + CODLIN_LIN + "' AND LINPPAL_LIN = 'S' ORDER BY NOMLIN_LIN";
                DataTable dt = mod.consulta(query);
                if (dt.Rows.Count > 0)
                {
                    NOMLIN_LIN = dt.Rows[0][1].ToString();
                }
                else
                {
                    NOMLIN_LIN = "";
                }
                return dt;
            }catch (Exception e) { throw e; }
        }

        public DataTable ConsultaLineas()
        {
            try
            {
                string query = "select codlin_lin as Codigo, nomlin_lin as Nombre from USU_FBR.MAELIN where LINPPAL_LIN = 'S' ORDER BY NOMLIN_LIN";
                DataTable dt = mod.consulta(query);
                if (dt.Rows.Count > 0)
                {
                    NOMLIN_LIN = dt.Rows[0][1].ToString();
                }
                else
                {
                    NOMLIN_LIN = "";
                }
                return dt;
            }
            catch (Exception e) { throw e; }
        }

        public void LimpiarValores()
        {
            CODLIN_LIN = "";
            NOMLIN_LIN = "";
            LOGSELECCIONADO = false;
        }

        public List<CLSMAELIN> ListarLineas() 
        {
            try 
            {
                string query = "select codlin_lin, nomlin_lin from USU_FBR.MAELIN WHERE LINPPAL_LIN = 'S' ORDER BY NOMLIN_LIN";
                List<CLSMAELIN> lis = new List<CLSMAELIN>();
                DataTable val = mod.consulta(query);
                foreach (DataRow r in val.Rows) 
                {
                    lis.Add(new CLSMAELIN 
                    {
                        CODLIN_LIN = r["CODLIN_LIN"].ToString(),
                        NOMLIN_LIN = r["NOMLIN_LIN"].ToString(),
                        LOGSELECCIONADO = true
                    });
                }
                return lis;
            }
            catch (Exception ex) { throw ex; }
        }

    }
}
